// 判断是否登录
$(async function(){
    let business = cookie.get('business') ? cookie.get('business') : null;

    //try catch 捕捉异常
    try{
        business = JSON.parse(business)
    }catch(err)
    {
        business = null
    }

    if(!business || JSON.stringify(business) == "{}")
    {
        cookie.clear()
        mui.toast('非法登录,请先登录', {duration: 1000})
        setTimeout(() => {
            location.href = 'login.html'
        }, 1000)
        return false
    }

    //组装数据
    let CheckData = {
        id: business.id ? business.id : 0,
        mobile: business.mobile ? business.mobile : ''
    }

    // 请求数据
    let result = await POST({
        url: '/business/check',
        params: CheckData
    })

    //判断用户是否存在，是不是伪造的cookie信息
    if(!result.code)
    {
        mui.toast(result.msg, {duration: 1000})
        cookie.clear()
        setTimeout(() => {
            location.href = 'login.html'
        }, 1000)
        return false
    }else
    {
        cookie.set('business', JSON.stringify(result.data))
    }
}());